import React from 'react';
import { Row, Col, Modal, Button, Input, message, Table, Form } from 'antd';
import {  WeaTools, WeaSelect, WeaBrowser, WeaLocaleProvider, WeaDialog, WeaError,WeaInputNumber } from 'ecCom';
import jQuery from "jquery";
import { observer } from 'mobx-react';
import { ShareStoreProps } from '../../stores/list/ShareStore';
import './style/index.css';
const FormItem = Form.Item;
const InputGroup = Input.Group;
const confirm = Modal.confirm;
const getLabel = WeaLocaleProvider.getLabel;

export interface SingleShareProps {
    billid: string;
    formId: string;
    modeId: string;
    type: string;
    inputStyle?: any;
    visible?: boolean;
    defaultShared?: boolean;
    nonDefaultShared?: boolean;
    icon?: string;
    title?: string;
    iconBgcolor?: string;
    onClose: Function;
    iconInfo: any;
}
export interface SingleShareState {
    _visible?: boolean;
    selectedRowKeys: string[];
    shareDataList: any[];
    labels: any;
    columns: any[];
    shareData: any;
    shareFieldMap:any,
    pageSize: number;
    addData: any;
    addDataInit: any;
    seclevelMin: number;
    seclevelMax: number;
    maxShare: number;
    appDetachDisableAll:boolean;
}

export default class SingleShare extends React.Component<SingleShareProps, SingleShareState> {
    refObj: any = {};
    constructor(props) {
        super(props);
        this.state = {
            labels: {},
            columns: [],
            shareData: { HrmCompanyVirtual: "0", shareType: "1", rightType: "1", isRoleLimited: "0", rolelevel: "0", showlevel: "0", joblevel: "2", rolefieldtype: "1" },
            selectedRowKeys: [],
            pageSize: 10,
            _visible: false,
            addData: {},
            addDataInit: {},
            seclevelMin: 0,
            seclevelMax: 100,
            shareDataList: [],
            shareFieldMap:{},
            appDetachDisableAll:false,
            maxShare: 0,
        }
    }
    componentDidMount() {
        let { billid, formId, modeId, type } = this.props;
        //初始化数据
        WeaTools.callApi('/api/formmode/card/getShareData', 'POST', { billid, formId, modeId, type }).then(datas => {
            const { shareDataList,appDetachDisableAll,shareFieldMap } = datas;
            this.setState({ shareDataList: shareDataList ,appDetachDisableAll:appDetachDisableAll,shareFieldMap:shareFieldMap});
        });
        //获取当前操作人的最大操作权限
        WeaTools.callApi('/api/formmode/card/right', 'POST', { billid, formId, modeId, type }).then(datas => {
            const { MaxShare } = datas;
            this.setState({ maxShare: MaxShare });
        });
    }

    render() {
        const { visible = false, defaultShared, nonDefaultShared, iconInfo = {} } = this.props;
        const { _visible, selectedRowKeys, shareDataList } = this.state;
        const buttons = [];//底部按钮预留 
        const _buttons = [
            <Button key="submit" type="primary" size="large" onClick={this._onOk} >{getLabel(86, '保存')}</Button>,
            <Button key="back" type="ghost" size="large" onClick={this._onCancel}>{getLabel(201, "取消")}</Button>
        ];
        const columns = [{
            title: getLabel(31248, '共享来源'),
            dataIndex: 'source',
            width: 90
        }, {
            title: getLabel(18495, '共享类型'),
            dataIndex: 'type',
            render: this.remderShareType,
            width: 250
        }, {
            title: getLabel(3005, '共享级别'),
            dataIndex: 'level',
            width: 250,
            render: (_, record) => (
                <div dangerouslySetInnerHTML={{ __html: record.level }} />
            )
        }, {
            title: getLabel(19117, '共享对象'),
            dataIndex: 'object',
            render: (_, record) => (
                <div style={{ maxWidth: "300px" }} dangerouslySetInnerHTML={{ __html: record.relatedShareNames }} />
            )
        }, {
            title: getLabel(385, '权限'),
            dataIndex: 'right',
            width: 90
        }] as any[]
        return (
            <div className='wea-mode-share'>
                <WeaDialog
                    className='wea-hr-muti-input wea-cube-muti-input'
                    buttons={buttons}
                    title={this.getTitle()}
                    iconBgcolor={iconInfo.iconBg || "#96358a"}
                    icon={iconInfo.icon || 'icon-coms-ModelingEngine'}
                    iconFontColor={iconInfo.iconColor || "#fff"}
                    visible={visible}
                    style={{ width: 900, height: 500 }}
                    hasScroll={true}
                    onCancel={this.onCancel}
                >
                    <div className='wea-table-edit wea-mode-share-table' style={{ height: 460 }}>
                        <Row className="wea-table-edit-title" >
                            <Col>
                                {getLabel(26137, '共享权限')}
                                {(nonDefaultShared || defaultShared) && <Button type="primary" disabled={!`${selectedRowKeys}`} {...{ title: getLabel(91, "删除") }} size="small" onClick={this.doDelete.bind(this, selectedRowKeys)} ><i className="icon-coms-form-delete-hot" /></Button>}
                                {nonDefaultShared && <Button type="primary" {...{ title: getLabel(1421, '新增') }} size="small" onClick={this.doAdd}><i className="icon-coms-Add-to-hot" /></Button>}
                            </Col>
                        </Row>
                        <Table
                            columns={columns}
                            dataSource={shareDataList}
                            pagination={false}
                            rowSelection={this.getRowSelection()}
                            scroll={{ y: 372 }}
                        />
                    </div>
                    <WeaDialog
                        className='wea-hr-muti-input'
                        buttons={_buttons}
                        title={this.getTitle(true)}
                        iconBgcolor={iconInfo.iconBg || "#96358a"}
                        icon={iconInfo.icon || 'icon-coms-ModelingEngine'}
                        iconFontColor={iconInfo.iconColor || "#fff"}
                        visible={_visible}
                        style={{ width: 650, height: 350 }}
                        hasScroll={true}
                        onCancel={this._onCancel}
                    >
                        {this.getAddComponent()}
                    </WeaDialog>
                </WeaDialog>
            </div>
        );
    }

    remderShareType = (text, record, _) => {
        if (record.islink) {
            return (
                <span>
                    {record.typeTopStr}<a href={record.typeHrefStr} target="_blank">{record.typeTitleStr}</a>{record.typeEndStr}
                </span>
            );
        } else {
            return text;
        }
    }

    changeSelect = (field, value) => {
        const shareData = jQuery.extend(true, {}, this.state.shareData);
        shareData[field] = value;
        if (field == "rolefieldtype") {
            shareData.rolefieldvlaue = "";
            shareData.rolefield = new Array();
        }
        this.setState({ shareData: shareData })
    }

    changeBrowserField = (field, ids, _, datas) => {
        const { shareData } = this.state;
        shareData[field] = datas;
        shareData[field + "value"] = ids;
        this.setState({ shareData: shareData })
    }

    changeLevel = (field, value) => {
        const { shareData } = this.state;
        shareData[field] = value;
        this.setState({ shareData: shareData })
    }

    getShareTypeOptions =()=>{
        const { shareData,appDetachDisableAll } = this.state
        let options=[
            { key: "1", selected: shareData.shareType == "1" || !shareData.shareType, showname: getLabel(1867, "人员") },
            { key: "2", selected: shareData.shareType == "2", showname: getLabel(141, "分部") },
            { key: "3", selected: shareData.shareType == "3", showname: getLabel(124, "部门") },
            { key: "4", selected: shareData.shareType == "4", showname: getLabel(122, "角色") },
            { key: "5", selected: shareData.shareType == "5", showname: getLabel(1340, "所有人") },
            { key: "6", selected: shareData.shareType == "6", showname: getLabel(6086, "岗位") }
        ]
        if(appDetachDisableAll){//禁用所有人
            options.splice(4,1);
        }
        return options;
    }
    getShareTypeOptionsForRole =()=>{
        console
        const { shareData,shareFieldMap } = this.state
        let options=[];
        if(shareData.rolefieldtype == "1" || !shareData.rolefieldtype){
            options=shareFieldMap && shareFieldMap.optionListForHrm;
        }else if(shareData.rolefieldtype == "2"){
            options=shareFieldMap && shareFieldMap.optionListForDep;
        }else if(shareData.rolefieldtype == "3"){
            options=shareFieldMap && shareFieldMap.optionListForSub;
        }
        return options;
    }

    getAddComponent() {
        const { shareData } = this.state
        const { maxShare } = this.state
        let shareType = shareData.shareType ? shareData.shareType : "1";
        let style = { marginBottom: 10 };
        let roleDataParams = {} as any;
        if (shareData.isRoleLimited == "1") {
            let rolefieldtype = shareData.rolefieldtype
            roleDataParams.formId = this.props.formId;
            roleDataParams.modeId = this.props.modeId;
            roleDataParams.fieldHtmlType = "3";
            roleDataParams.isRoleLimited = "1";
            roleDataParams.rolefieldtype = rolefieldtype ? rolefieldtype : "1";
            roleDataParams.fieldType = rolefieldtype == "3" ? "170,169,164,194" : (rolefieldtype == "2" ? "168,167,57,4" : "166,165,17,1")
        }
        const shareOptions = [
            { key: "1", selected: shareData.rightType == "1" || !shareData.rightType, showname: getLabel(367, "查看") },
        ];
        if (maxShare > 1) {
            shareOptions.push({ key: "2", selected: shareData.rightType == "2", showname: getLabel(93, "编辑") });
            if (maxShare > 2) {
                shareOptions.push({ key: "3", selected: shareData.rightType == "3", showname: getLabel(17874, "完全控制") });
            }
        }
        const options=this.getShareTypeOptions();
        const optionsForRole=this.getShareTypeOptionsForRole();
        return (<div style={{ padding: 20 }}>
            <Form>
                <FormItem
                    style={style}
                    label={getLabel(18495, "共享类型")}
                    labelCol={{ span: 6 }}
                    wrapperCol={{ span: 12 }}>
                    <div style={{ float: "left" }}>
                        <WeaSelect
                            fieldName="shareType"
                            options={options}
                            value={shareData.shareType}
                            style={{ width: "100px" }}
                            onChange={(vlaue) => { this.changeSelect("shareType", vlaue) }}
                        >
                        </WeaSelect>
                    </div>
                    {(shareType == "2" || shareType == "3") &&
                        <div style={{ position: "absolute", left: "120px"}}>
                            <WeaSelect
                                fieldName="orgrelation"
                                options={[
                                    { key: "0", selected: shareData.orgrelation == "0" || !shareData.orgrelation, showname: "" },
                                    { key: "1", selected: shareData.orgrelation == "1", showname: getLabel(15762, "所有上级") },
                                    { key: "2", selected: shareData.orgrelation == "2", showname: getLabel(15765, "所有下级") }
                                ]}
                                value={shareData.orgrelation}
                                style={{ width: "100px" }}
                                onChange={(vlaue) => { this.changeSelect("orgrelation", vlaue) }}
                            >
                            </WeaSelect>
                        </div>}
                </FormItem>

                {
                    shareType == "1" && <FormItem
                        style={style}
                        label={getLabel(172, "选择")}
                        labelCol={{ span: 6 }}
                        wrapperCol={{ span: 10 }}>
                        <WeaError tipPosition='bottom'
                            error={getLabel(172, "选择") + getLabel(1867, "人员") + getLabel(21423, "未填写")}
                            style={{ width: "100%" }}
                            ref={ref => { this.refObj["relatedid1"] = ref; }}
                        >
                            <WeaBrowser
                                type="17"
                                title={getLabel(1867, "人员")}
                                fieldName="relatedid1"
                                viewAttr="3"
                                isSingle={false}
                                replaceDatas={shareData.relatedid1 ? shareData.relatedid1 : new Array()}
                                onChange={(ids, names, datas) => { this.changeBrowserField("relatedid1", ids, names, datas) }}
                            />
                        </WeaError>
                    </FormItem>
                }

                {
                    shareType == "2" && <FormItem
                        style={style}
                        label={getLabel(172, "选择")}
                        labelCol={{ span: 6 }}
                        wrapperCol={{ span: 10 }}>
                        <WeaError tipPosition='bottom'
                            error={getLabel(172, "选择") + getLabel(141, "分部") + getLabel(21423, "未填写")}
                            style={{ width: "100%" }}
                            ref={ref => { this.refObj["relatedid2"] = ref; }}
                        >
                            <WeaBrowser
                                type="194"
                                title={getLabel(141, "分部")}
                                fieldName="relatedid2"
                                viewAttr="3"
                                isSingle={false}
                                replaceDatas={shareData.relatedid2 ? shareData.relatedid2 : new Array()}
                                onChange={(ids, names, datas) => { this.changeBrowserField("relatedid2", ids, names, datas) }}
                            />
                        </WeaError>
                    </FormItem>
                }

                {
                    shareType == "3" && <FormItem
                        style={style}
                        label={getLabel(172, "选择")}
                        labelCol={{ span: 6 }}
                        wrapperCol={{ span: 10 }}>
                        <WeaError tipPosition='bottom'
                            error={getLabel(172, "选择") + getLabel(124, "部门") + getLabel(21423, "未填写")}
                            style={{ width: "100%" }}
                            ref={ref => { this.refObj["relatedid3"] = ref; }}
                        >
                            <WeaBrowser
                                type="57"
                                title={getLabel(124, "部门")}
                                fieldName="relatedid3"
                                viewAttr="3"
                                isSingle={false}
                                replaceDatas={shareData.relatedid3 ? shareData.relatedid3 : new Array()}
                                onChange={(ids, names, datas) => { this.changeBrowserField("relatedid3", ids, names, datas) }}
                            />
                        </WeaError>
                    </FormItem>
                }
                {
                    shareType == "4" && <FormItem
                        style={style}
                        label={getLabel(172, "选择")}
                        labelCol={{ span: 6 }}
                        wrapperCol={{ span: 10 }}>
                        <WeaError tipPosition='bottom'
                            error={getLabel(172, "选择") + getLabel(122, "角色") + getLabel(21423, "未填写")}
                            style={{ width: "100%" }}
                            ref={ref => { this.refObj["relatedid4"] = ref; }}
                        >
                            <WeaBrowser
                                type="65"
                                title={getLabel(122, "角色")}
                                fieldName="relatedid4"
                                viewAttr="3"
                                isSingle={false}
                                replaceDatas={shareData.relatedid4 ? shareData.relatedid4 : new Array()}
                                onChange={(ids, names, datas) => { this.changeBrowserField("relatedid4", ids, names, datas) }}
                            />
                        </WeaError>
                    </FormItem>
                }
                {
                    shareType == "6" && <FormItem
                        style={style}
                        label={getLabel(172, "选择")}
                        labelCol={{ span: 6 }}
                        wrapperCol={{ span: 10 }}>
                        <WeaError tipPosition='bottom'
                            error={getLabel(172, "选择") + getLabel(6086, "岗位") + getLabel(21423, "未填写")}
                            style={{ width: "100%" }}
                            ref={ref => { this.refObj["relatedid6"] = ref; }}
                        >
                            <WeaBrowser
                                type="278"
                                title={getLabel(6086, "岗位")}
                                fieldName="relatedid6"
                                viewAttr="3"
                                isSingle={false}
                                replaceDatas={shareData.relatedid6 ? shareData.relatedid6 : new Array()}
                                onChange={(ids, names, datas) => { this.changeBrowserField("relatedid6", ids, names, datas) }}
                            />
                        </WeaError>
                    </FormItem>
                }
                {
                    shareType == "4" && <FormItem
                        style={style}
                        label={getLabel(82385, '角色是否受范围限制')}
                        labelCol={{ span: 6 }}
                        wrapperCol={{ span: 6 }}>
                        <WeaSelect
                            fieldName="isRoleLimited"
                            options={[
                                { key: "0", selected: shareData.isRoleLimited == "0" || !shareData.isRoleLimited, showname: getLabel(161, "否") },
                                { key: "1", selected: shareData.isRoleLimited == "1", showname: getLabel(163, "是") }
                            ]}
                            value={shareData.isRoleLimited}
                            style={{ width: "100px" }}
                            onChange={(vlaue) => { this.changeSelect("isRoleLimited", vlaue) }}
                        >
                        </WeaSelect>
                    </FormItem>
                }

                {
                    shareType == "4" && shareData.isRoleLimited == "1" && <FormItem
                        style={style}
                        label={getLabel(686, "字段类型")}
                        labelCol={{ span: 6 }}
                        wrapperCol={{ span: 16 }}>
                        <InputGroup>
                            <Col span={5}>
                                <WeaSelect
                                    fieldName="rolefieldtype"
                                    options={[
                                        { key: "1", selected: shareData.rolefieldtype == "1" || !shareData.rolefieldtype, showname: getLabel(1867, "人员") },
                                        { key: "2", selected: shareData.rolefieldtype == "2", showname: getLabel(124, "部门") },
                                        { key: "3", selected: shareData.rolefieldtype == "3", showname: getLabel(141, "分部") }
                                    ]}
                                    value={shareData.rolefieldtype}
                                    //style={{ width: "50%" }}
                                    onChange={(vlaue) => { this.changeSelect("rolefieldtype", vlaue) }}
                                >
                                </WeaSelect>
                            </Col>
                        </InputGroup>
                    </FormItem>
                }

                {
                    shareType == "4" && shareData.isRoleLimited == "1" && <FormItem
                        style={style}
                        label={getLabel(82386, "限制字段")}
                        labelCol={{ span: 6 }}
                        wrapperCol={{ span: 16 }}>
                        <InputGroup>
                            <Col span={10}>
                                <WeaError tipPosition='bottom'
                                    error={getLabel(82386, "限制字段") + getLabel(21423, "未填写")}
                                    style={{ width: "200px" }}
                                    ref={ref => { this.refObj["rolefield"] = ref; }}
                                >
                                    <WeaSelect
                                        fieldName="rolefield"
                                        options={optionsForRole}
                                        value={shareData.rolefield}
                                        viewAttr="3"
                                        style={{ width: "100%" }}
                                        onChange={(vlaue) => { this.changeSelect("rolefield", vlaue) }}
                                    >
                                    </WeaSelect>
                                </WeaError>
                            </Col>
                        </InputGroup>
                    </FormItem>
                }

                {
                    shareType == "4" && <FormItem
                        style={style}
                        label={getLabel(3005, "共享级别")}
                        labelCol={{ span: 6 }}
                        wrapperCol={{ span: 6 }}>
                        <WeaSelect
                            fieldName="rolelevel"
                            options={[
                                { key: "0", selected: shareData.rolelevel == "0" || !shareData.rolelevel, showname: getLabel(124, "部门") },
                                { key: "1", selected: shareData.rolelevel == "1", showname: getLabel(141, "分部") },
                                { key: "2", selected: shareData.rolelevel == "2", showname: getLabel(140, "总部") },
                            ]}
                            value={shareData.rolelevel}
                            style={{ width: "100px" }}
                            onChange={(vlaue) => { this.changeSelect("rolelevel", vlaue) }}
                        >
                        </WeaSelect>
                    </FormItem>
                }

                {
                    shareType == "6" && <FormItem
                        style={style}
                        label={getLabel(28169, "岗位级别")}
                        labelCol={{ span: 6 }}
                        wrapperCol={{ span: 16 }}>
                        <InputGroup>
                            <Col span={5}>
                                <WeaSelect
                                    fieldName="joblevel"
                                    options={[
                                        { key: "0", selected: shareData.joblevel == "0", showname: getLabel(19438, "指定部门") },
                                        { key: "1", selected: shareData.joblevel == "1", showname: getLabel(19437, "指定分部") },
                                        { key: "2", selected: shareData.joblevel == "2" || !shareData.joblevel, showname: getLabel(140, "总部") },
                                    ]}
                                    value={shareData.joblevel}
                                    //style={{ width: "50%" }}
                                    onChange={(vlaue) => { this.changeSelect("joblevel", vlaue) }}
                                >
                                </WeaSelect>
                            </Col>
                        </InputGroup>
                    </FormItem>
                }

                {
                    shareType == "6" && (shareData.joblevel == "0" || shareData.joblevel == "1") && <FormItem
                        style={style}
                        label={shareData.joblevel == "0" ? getLabel(19438, "指定部门") : getLabel(19437, "指定分部")}
                        labelCol={{ span: 6 }}
                        wrapperCol={{ span: 16 }}>
                        <InputGroup>
                            <Col span={5}>
                                {shareData.joblevel == "0" &&
                                    <WeaError tipPosition='bottom'
                                        error={getLabel(124, "部门") + getLabel(21423, "未填写")}
                                        style={{ width: "100%" }}
                                        ref={ref => { this.refObj["jobleveltext1"] = ref; }}
                                    >
                                        <WeaBrowser
                                            className="wea-cube-muti-browser-com"
                                            type="57"
                                            title={getLabel(124, "部门")}
                                            fieldName="jobleveltext1"
                                            viewAttr="3"
                                            isSingle={false}
                                            replaceDatas={shareData.jobleveltext1 ? shareData.jobleveltext1 : new Array()}
                                            onChange={(ids, names, datas) => { this.changeBrowserField("jobleveltext1", ids, names, datas) }}
                                        />
                                    </WeaError>}
                                {shareData.joblevel == "1" &&
                                    <WeaError tipPosition='bottom'
                                        error={getLabel(141, "分部") + getLabel(21423, "未填写")}
                                        style={{ width: "100%" }}
                                        ref={ref => { this.refObj["jobleveltext0"] = ref; }}
                                    >
                                        <WeaBrowser
                                            className="wea-cube-muti-browser-com"
                                            type="194"
                                            title={getLabel(141, "分部")}
                                            fieldName="jobleveltext0"
                                            viewAttr="3"
                                            isSingle={false}
                                            replaceDatas={shareData.jobleveltext0 ? shareData.jobleveltext0 : new Array()}
                                            onChange={(ids, names, datas) => { this.changeBrowserField("jobleveltext0", ids, names, datas) }}
                                        />
                                    </WeaError>}
                            </Col>
                        </InputGroup>
                    </FormItem>
                }
                {
                    shareType && shareType != "1" && <FormItem
                        style={style}
                        label={getLabel(683, "安全级别")}
                        labelCol={{ span: 6 }}
                        wrapperCol={{ span: 12 }}>
                        <InputGroup>
                            <Col span={8}>
                                <WeaError tipPosition='bottom'
                                    error={getLabel(683, "安全级别") + getLabel(21423, "未填写")}
                                    style={{ width: "100%" }}
                                    ref={ref => { this.refObj["showlevel"] = ref; }}
                                >
                                    <WeaInputNumber onChange={(v) => { this.changeLevel("showlevel", v) }} value={shareData.showlevel ? shareData.showlevel : ""} id="showlevel" fieldName="showlevel" name="showlevel" viewAttr="3" />
                                </WeaError>
                            </Col>
                            <Col span={2}>
                                <p className="ant-form-split">-</p>
                            </Col>
                            <Col span={8}>
                                <WeaInputNumber onChange={(v) => { this.changeLevel("showlevel2", v) }} value={shareData.showlevel2 ? shareData.showlevel2 : ""} id="showlevel2" fieldName="showlevel2" name="showlevel2" />
                            </Col>
                        </InputGroup>
                    </FormItem>
                }

                <FormItem
                    style={{ marginTop: -5, ...style }}
                    label={getLabel(440, "权限项")}
                    labelCol={{ span: 6 }}
                    wrapperCol={{ span: 6 }}>
                    <WeaSelect
                        fieldName="rightType"
                        options={shareOptions}
                        value={shareData.rightType}
                        style={{ width: "100px" }}
                        onChange={(vlaue) => { this.changeSelect("rightType", vlaue) }}
                    >
                    </WeaSelect>
                </FormItem>
            </Form >
        </div >)
    }

    getRowSelection = (): any => {
        const { columns, selectedRowKeys } = this.state;
        if (!`${columns} `) return null
        const { defaultShared, nonDefaultShared } = this.props;
        const rowSelection = {
            selectedRowKeys,
            onChange: (sRowKeys, _) => {
                this.setState({ selectedRowKeys: sRowKeys });
            },
            getCheckboxProps: (record) => {
                return {//默认共享不允许删除
                    disabled: record.isdefault == '1' ? !(defaultShared&&record.candel) : !nonDefaultShared, // Column configuration not to be checked
                }
            }
        }
        return rowSelection
    }

    //btns
    doAdd = () => {
        this.setState({ _visible: true })
    }

    doDelete = () => {
        const { selectedRowKeys } = this.state;
        const { billid, formId, modeId } = this.props;
        if (selectedRowKeys.length == 0) {
            Modal.info({
                title: getLabel(15172, '系统提示'),
                content: (
                    <div>
                        <p>{getLabel(31251, '请先选择需要删除的权限项！')}</p>
                    </div>
                ),
                onOk() { },
            });
        } else {
            confirm({
                title: getLabel(31250, '确认需要删除这些共享吗？'),
                onOk: () => {
                    WeaTools.callApi('/api/formmode/card/shareDataDel', 'POST', { billid, formId, modeId, delid: selectedRowKeys }).then(datas => {
                        const { shareDataList } = datas;
                        this.setState({ shareDataList: shareDataList, _visible: false });
                    });
                },
                onCancel() { },
            });
        }
    }
    getTitle(bool?: boolean) {
        const { title = getLabel(119, '共享') } = this.props;
        return (
            <div className="wea-hr-muti-input-title">
                <span style={{ verticalAlign: 'middle' }}>{bool ? getLabel(18645, '添加共享') : title}</span>
            </div>
        )
    }
    onCancel = () => {
        this.props.onClose();
    }
    _onOk = () => {
        const { shareData } = this.state;
        const { billid, formId, modeId } = this.props;
        if (this.checkSubmit()) {
            let shareType = shareData.shareType ? shareData.shareType : "1";
            shareData.relatedid = shareData["relatedid" + shareType + "value"];
            if (shareType == "4" && shareData.isRoleLimited == "1") {
                //shareData.rolefield = shareData.rolefieldvalue;
                let parm = { billid, formId, modeId, role: shareData.relatedid4value, rolefieldtype: shareData.rolefieldtype, rolefield: shareData.rolefield, rolelevel: shareData.rolelevel, showlevel: shareData.showlevel, showlevel2: shareData.showlevel2 ? shareData.showlevel2 : "" }
                WeaTools.callApi('/api/formmode/card/checkShareRole', 'POST', parm).then(datas => {
                    let canadd = datas.canadd;
                    if (canadd) {
                        WeaTools.callApi('/api/formmode/card/shareData', 'POST', { billid, formId, modeId, ...shareData }).then(datas => {
                            const { shareDataList } = datas;
                            this.setState({ shareDataList: shareDataList, _visible: false, shareData: { HrmCompanyVirtual: "0", shareType: "1", rightType: "1", isRoleLimited: "0", rolelevel: "0", showlevel: "0", joblevel: "3", rolefieldtype: "1" }, });
                        });
                    } else {
                        message.warning(getLabel(82469, '按照你的限制条件，在角色中没有满足条件的人员！'), 5);
                    }
                });
            } else {
                if (shareType == "6") {
                    if (shareData.joblevel == "0") {
                        shareData.jobleveltext = shareData.jobleveltext1value
                    } else if (shareData.joblevel == "1") {
                        shareData.jobleveltext = shareData.jobleveltext0value
                    }
                }
                WeaTools.callApi('/api/formmode/card/shareData', 'POST', { billid, formId, modeId, ...shareData }).then(datas => {
                    const { shareDataList } = datas;
                    this.setState({ shareDataList: shareDataList, _visible: false, shareData: { HrmCompanyVirtual: "0", shareType: "1", rightType: "1", isRoleLimited: "0", rolelevel: "0", showlevel: "0", joblevel: "2", rolefieldtype: "1" }, });
                });
            }
        }
    }

    checkSubmit = () => {
        const { shareData } = this.state;
        let shareType = shareData.shareType ? shareData.shareType : "1";
        let showlevel = jQuery.trim(shareData.showlevel);
        if (shareType == "1") {
            let relatedid1value = shareData.relatedid1value;
            if (!relatedid1value) {
                this.showError('relatedid1');
            }
            return relatedid1value
        } else if (shareType == "2") {
            let relatedid2value = shareData.relatedid2value;
            if (!relatedid2value) {
                this.showError('relatedid2');
            } else if (!showlevel) {
                this.showError('showlevel');
            }
            return relatedid2value && showlevel;
        } else if (shareType == "3") {
            let relatedid3value = shareData.relatedid3value;
            if (!relatedid3value) {
                this.showError('relatedid3');
            } else if (!showlevel) {
                this.showError('showlevel');
            }
            return relatedid3value && showlevel;
        } else if (shareType == "4") {
            let relatedid4value = shareData.relatedid4value;
            if (shareData.isRoleLimited == "1") {
                if (!relatedid4value) {
                    this.showError('relatedid4');
                } else if (!showlevel) {
                    this.showError('showlevel');
                } else if (!shareData.rolefield) {
                    console
                    this.showError('rolefield');
                }
                return relatedid4value && showlevel && shareData.rolefield && shareData.rolefieldtype
            } else {
                if (!relatedid4value) {
                    this.showError('relatedid4');
                } else if (!showlevel) {
                    this.showError('showlevel');
                }
                return relatedid4value && showlevel
            }
        } else if (shareType == "5") {
            if (!showlevel) {
                this.showError('showlevel');
            }
            return showlevel;
        } else if (shareType == "6") {
            let relatedid6value = shareData.relatedid6value;
            let joblevel = shareData.joblevel;
            if (joblevel == "0") {
                let jobleveltext1 = shareData.jobleveltext1;
                if (!relatedid6value) {
                    this.showError('relatedid6');
                } else if (!showlevel) {
                    this.showError('showlevel');
                } else if (!jobleveltext1) {
                    this.showError('jobleveltext1');
                }
                return relatedid6value && showlevel && jobleveltext1;
            } else if (joblevel == "1") {
                let jobleveltext0 = shareData.jobleveltext0;
                if (!relatedid6value) {
                    this.showError('relatedid6');
                } else if (!showlevel) {
                    this.showError('showlevel');
                } else if (!jobleveltext0) {
                    this.showError('jobleveltext0');
                }
                return relatedid6value && showlevel && jobleveltext0;
            } else {
                if (!relatedid6value) {
                    this.showError('relatedid6');
                } else if (!showlevel) {
                    this.showError('showlevel');
                }
                return relatedid6value && showlevel;
            }

        }
    }
    showError = (key) => {
        const domkeyRef = this.refObj[key];
        domkeyRef.showError();
        return false;
    }

    _onCancel = () => {
        this.setState({ _visible: false })
    }
}
export interface SingleShareDialogProps {
    formId: string;
    modeId: string;
    type: string;
    defaultShared?: boolean;
    nonDefaultShared?: boolean;
    share: ShareStoreProps;
    iconInfo: any;
}
@observer
export class SingleShareDialog extends React.Component<SingleShareDialogProps, any> {
    render() {
        const { share } = this.props;
        return (
            <div>
                {share.singleVisible && <SingleShare {...this.props} billid={share.billid} visible={share.singleVisible} onClose={share.closeSingle} />}
            </div>
        )
    }
}